package com.tarasenko.web.scope;

import java.util.concurrent.ConcurrentHashMap;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.event.PostConstructCustomScopeEvent;
import javax.faces.event.PreDestroyCustomScopeEvent;
import javax.faces.event.ScopeContext;

/** 
 */
public class TaskScope extends ConcurrentHashMap<String,Object> {

    private Application application;
    

    public TaskScope(Application application) {
        this.application = application;   
    }

    //будет вызывать метод postConstruct
    public void notifyCreate(String scopeName, FacesContext facesContext) {
        ScopeContext scopeContext = new ScopeContext(scopeName, this);
        application.publishEvent(facesContext, PostConstructCustomScopeEvent.class, scopeContext);
    }

    //удет вызывать метод preDestroy.
    public void notifyDestroy(String scopeName, FacesContext facesContext) {
        ScopeContext scopeContext = new ScopeContext(scopeName, this);
        application.publishEvent(facesContext, PreDestroyCustomScopeEvent.class, scopeContext);
    }

}
